//
//  StatefulViewController.swift
//  YPWatermarkCamera
//
//  Created by yupao_ios_macmini06 on 2022/11/1.
//

import UIKit

// MARK: - [WmcStatefulViewControllerState]

/// 占位视图状态
enum WmcStatefulViewControllerState: String {
    case content
    case loading
    case error
    case empty
}

// MARK: - [WmcBackingViewProvider]

protocol WmcBackingViewProvider {
    var backingView: UIView { get }
}

// MARK: - [WmcStatefulViewController]

protocol WmcStatefulViewController: AnyObject, WmcBackingViewProvider {
    var stateMachine: WmcViewStateMachine { get }

    var currentState: WmcStatefulViewControllerState { get }

    var lastState: WmcStatefulViewControllerState { get }

    // MARK: Views

    var loadingView: UIView? { get set }

    var errorView: UIView? { get set }

    var emptyView: UIView? { get set }

    // MARK: Transitions

    func setupInitialViewState(_ completion: (() -> Void)?)

    func startLoading(animated: Bool, completion: (() -> Void)?)

    func endLoading(animated: Bool, error: Error?, completion: (() -> Void)?)

    func transitionViewStates(loading: Bool, error: Error?, animated: Bool, completion: (() -> Void)?)

    // MARK: Content and error handling

    func hasContent() -> Bool

    func handleErrorWhenContentAvailable(_ error: Error)
}
